<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<title>Mac转IPv6</title>
		<script>
		var check=function(array){
			if(array.length!=6)return false;
			var b=true;
			for (i=0;i<array.length;i++){
				var k=parseInt(array[i],16);
				//console.log(k);
				b=b&&(k>=0&&k<=255);
			}
			//console.log(b);
			return b;
		}
		var go=function(){
			var input = document.getElementById('input_mac').value.trim();
			var input=input.replaceAll("-",":").split(":");
			var outDiv=document.getElementById('result');	
			if(check(input)){
				var first=parseInt(input[0], 16)^2;
				var output="fe80::"+first.toString(16)+input[1]+":"+input[2]+"ff:fe"+input[3]+":"+input[4]+input[5];
				var ipv6=output.toLowerCase();
				outDiv.innerText ="IPv6(EUI-64)地址: "+ipv6+"\n"+"Http地址: http://["+ipv6+"]"+"\n"+"Http地址: http://["+ipv6+"]:80";
			}else{
				outDiv.innerText="转换失败，请检查格式是否正确!"
			}
		}
		</script>
	</head>
	<body>
		<h5>Mac转IPv6</h5>
		<input id="input_mac" type="text" placeholder="Mac地址" autocomplete="off"/>
		<button id="go" onclick="go()" type="button">转换</button>
		<div id="result"/>
	</body>
</html>